/*
 ============================================================================
 Name		: NiFrameworkAppView.cpp
 Author	  : nmj
 Copyright   : Your copyright notice
 Description : Application view implementation
 ============================================================================
 */

// INCLUDE FILES
#include <coemain.h>
#include "NiFrameworkAppView.h"
#include "NiContainer.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CNiFrameworkAppView* CNiFrameworkAppView::NewL(const TRect& aRect)
{
	CNiFrameworkAppView* self = CNiFrameworkAppView::NewLC(aRect);
	CleanupStack::Pop(self);
	return self;
}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CNiFrameworkAppView* CNiFrameworkAppView::NewLC(const TRect& aRect)
{
	CNiFrameworkAppView* self = new (ELeave) CNiFrameworkAppView;
	CleanupStack::PushL(self);
	self->ConstructL(aRect);
	return self;
}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CNiFrameworkAppView::ConstructL(const TRect& aRect)
{
	// Create a window for this application view
	CreateWindowL();

	iContainer = CNiContainer::NewL(aRect, this);

	// Set the windows size
	SetRect(aRect);

	// Activate the window, which makes it ready to be drawn
	ActivateL();
}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::CNiFrameworkAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CNiFrameworkAppView::CNiFrameworkAppView()
{
	// No implementation required
}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::~CNiFrameworkAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CNiFrameworkAppView::~CNiFrameworkAppView()
{
	delete iContainer;
}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CNiFrameworkAppView::Draw(const TRect& /*aRect*/) const
{
	// Get the standard graphics context
	CWindowGc& gc = SystemGc();

	// Gets the control's extent
	TRect drawRect(Rect());

	// Clears the screen
	gc.Clear(drawRect);

}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CNiFrameworkAppView::SizeChanged()
{
	iContainer->SetExtent( TPoint(0,0), iContainer->MinimumSize());
	DrawNow();
}

// -----------------------------------------------------------------------------
// CNiFrameworkAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// Note: although this method is compatible with earlier SDKs, 
// it will not be called in SDKs without Touch support.
// -----------------------------------------------------------------------------
//
void CNiFrameworkAppView::HandlePointerEventL(
		const TPointerEvent& aPointerEvent)
{

	// Call base class HandlePointerEventL()
	CCoeControl::HandlePointerEventL(aPointerEvent);
}

TInt CNiFrameworkAppView::CountComponentControls() const
{
	return 1;
}
	
CCoeControl* CNiFrameworkAppView::ComponentControl(TInt aIndex) const
{
	switch ( aIndex )
	{
	case 0:
		return iContainer;
	default:
		return NULL;
	}
}

// End of File
